﻿package cn.jekun.shop.web.action;

import javax.annotation.Resource;

import net.sf.json.JSONObject;
import cn.jekun.component.base.bean.ErrorMsg;
import cn.jekun.component.base.exceptions.BusinessException;
import cn.jekun.shop.common.service.ShopBaseAction;
import cn.jekun.shop.common.service.ShopTypeService;
/**
 * 商家类型展示
 * @author twj
 *
 */
@SuppressWarnings("serial")
public class ShopsTypeAction extends ShopBaseAction{
	@Resource(name = ShopTypeService.BEAN_NAME)
	ShopTypeService shopTypeService;
	/**
	 * 商家类型展示
	 * @return
	 */
	public String showShopsTypes(){
		JSONObject jsonObject = null;
		try {
			String parentId = this.request.getParameter("parentId");
			jsonObject = shopTypeService.showShopTypes(parentId);
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	
	
	/**
	 * 商家展示
	 * @return    7月28 号加入
	 */
	public String showShops(){
		JSONObject jsonObject = null;
		try {
			String address = this.request.getParameter("address");
			jsonObject = shopTypeService.showShops(address);
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	
	
	
	
	
	
	/**
	 *  查询所有分类
	 * @return
	 */
	public String showAllShopsTypes(){
		JSONObject jsonObject = null;
		try {
			jsonObject = shopTypeService.showAllShopTypes();
		} catch (BusinessException e) {
			// TODO: handle exception
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}

}
